package com.handpay.zztong.hp.notification.model;

import android.content.Context;

import com.handpay.framework.utils.CommonUtils;
import com.handpay.zztong.hp.base.model.base.BaseModel;
import com.handpay.zztong.hp.db.ormlite.DataBasePushMessageModel;
import com.handpay.zztong.hp.log.HPLog;
import com.handpay.zztong.hp.notification.bean.PushMessgaeBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by fplei on 2017/5/17.
 */

public class PushMessageModel extends BaseModel{
    private static PushMessageModel pushMessageModel=null;
    private DataBasePushMessageModel dataBasePushMessageModel=null;

    /**
     * 实例化model，因为在其他类需要使用该实例，因此Context最好为applicationContext
     * @return
     */
    public static  PushMessageModel getInstance(){
        if(pushMessageModel==null){
            pushMessageModel=new PushMessageModel();
        }
        return pushMessageModel;
    }

    public void builder(Context mContext){
        dataBasePushMessageModel=DataBasePushMessageModel.getInstance(mContext);
    }

    public List<PushMessgaeBody> getTestPushMessages(){
        List<PushMessgaeBody> datas=new ArrayList<>();
        for (int i=0;i<10;i++){
            PushMessgaeBody pm=new PushMessgaeBody();
            pm.setTitle("即时消息");
            pm.setTime("2017-05-17");
            pm.setContent("测试即时消息，紧急通知!紧急通知!紧急通知\n您2017年5月16日做的一笔交易被冻结，为了防止资金被冻结，请尽快与公司客服取得联系！"+i);
            datas.add(pm);
        }
        return datas;
    }

    /**
     * 查询推送消息
     * @param userId
     * @return
     */
    public List<PushMessgaeBody> getPushMessages(String userId){
        HPLog.i(HPLog.TAG_RESULT,"getPushMessages---userId:"+userId);
        if(dataBasePushMessageModel==null)return null;
        return dataBasePushMessageModel.queryMessages(userId);
    }
    /**
     * 添加一条消息
     * @param messgaeBody
     */
    public void addPushMessage(PushMessgaeBody messgaeBody){
        if(dataBasePushMessageModel==null)return;
        dataBasePushMessageModel.addMessage(messgaeBody);
    }
}
